<html>
<head><meta charset="utf-8"><title>loose notes on my mental model of initialization · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html">loose notes on my mental model of initialization</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="165289171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165289171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165289171">(May 09 2019 at 21:09)</a>:</h4>
<p>Was trying to work out how ManuallyDrop is supposed to actually be defined, wrote out some thoughts which might be interesting, or worth desensitizing me from, in the case that I need to write proper docs for these things: <a href="https://gist.github.com/Gankro/5a62f7b5a62e84b9c299f72d2ce9c33c" target="_blank" title="https://gist.github.com/Gankro/5a62f7b5a62e84b9c299f72d2ce9c33c">https://gist.github.com/Gankro/5a62f7b5a62e84b9c299f72d2ce9c33c</a></p>



<a name="165295909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165295909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165295909">(May 09 2019 at 23:12)</a>:</h4>
<p>seems reasonable, although I don't understand what the special case with local variables is, and I don't think double dropping on things that don't have drop glue is bad; basically, you should be able to do anything with a deinit variable, except for do anything logical with it's fields? maybe? I don't know if it's actually useful to have a non-library concept of "dropped"</p>



<a name="165296002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296002">(May 09 2019 at 23:14)</a>:</h4>
<p>I needed to be careful that <code>let x: bool;</code> was not the same <code>let x: bool = unintialized()</code>, since the former is obviously fine, and the latter is insta-ub</p>



<a name="165296005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296005">(May 09 2019 at 23:14)</a>:</h4>
<p>personally, I'm of the opinion from the top of my head that the destructor is simply a function you call</p>



<a name="165296038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296038">(May 09 2019 at 23:15)</a>:</h4>
<p>But it has the library guarantee (that the language enforces where it can) that it's not called twice without reinitialization</p>



<a name="165296041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296041">(May 09 2019 at 23:15)</a>:</h4>
<p>right</p>



<a name="165296048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296048">(May 09 2019 at 23:15)</a>:</h4>
<p>so it's a library concept, not a language concept</p>



<a name="165296068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296068">(May 09 2019 at 23:16)</a>:</h4>
<p>like, if you wanted to define a type for which double-drops are fine, and then call <code>drop_in_place</code> on it twice, that should be fine in my un-thought-through opinion</p>



<a name="165296110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296110">(May 09 2019 at 23:16)</a>:</h4>
<p>i.e., <code>let x = 0; drop_in_place(&amp;mut x);</code> should probably be fine</p>



<a name="165296115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296115">(May 09 2019 at 23:16)</a>:</h4>
<p>Agreed</p>



<a name="165296121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296121">(May 09 2019 at 23:16)</a>:</h4>
<p>Although it's not super clear why that is at all useful</p>



<a name="165296132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296132">(May 09 2019 at 23:16)</a>:</h4>
<p>other than just "less ub"</p>



<a name="165296136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296136">(May 09 2019 at 23:16)</a>:</h4>
<p>I mean, I think it's more like it's not useful to make it UB</p>



<a name="165296155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296155">(May 09 2019 at 23:17)</a>:</h4>
<p>if you don't have any reason to make something UB, why complexify your model to make it UB?</p>



<a name="165296229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296229">(May 09 2019 at 23:18)</a>:</h4>
<p>there's a world where the compiler could prove something on the basis that the opposite implies a double-drop</p>



<a name="165296234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296234">(May 09 2019 at 23:18)</a>:</h4>
<p>I guess</p>



<a name="165296238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296238">(May 09 2019 at 23:18)</a>:</h4>
<p>doesn't seem _that_ useful for opts tho</p>



<a name="165296305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296305">(May 09 2019 at 23:19)</a>:</h4>
<p>no, but it wasn't obvious until I wrote it out that it's possible to make a consistent model where we don't just say it's UB</p>



<a name="165296373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165296373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165296373">(May 09 2019 at 23:20)</a>:</h4>
<p>as in, it might be if dropping created mem::uninit</p>



<a name="165315063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165315063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165315063">(May 10 2019 at 07:13)</a>:</h4>
<p>hm, I dont think we want "deinit" on the lang level -- is that what you have been arguing about? (it seemed more about <code>drop</code>)</p>



<a name="165315175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165315175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165315175">(May 10 2019 at 07:15)</a>:</h4>
<blockquote>
<p>If we have a value: T = uninit, the compiler may adversarially assume any bit patterns, which subsequently means that if T's bitwise or logical constraints are non-empty, Behaviour is Undefined.</p>
</blockquote>
<p>I find this double-negation ("non-empty contraints") to be hard to understand -- what is even formally a constraint? the complement of the invariant?</p>



<a name="165315256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165315256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165315256">(May 10 2019 at 07:17)</a>:</h4>
<p>your "logical constraints" seem to be "between" my validity/initialization invariant and my safety invariant. However, they all seem to be ptr-related, so they basically just refer to Stacked Borrows. I've been wondering if Stacked Borrows should "enter" <code>ManuallyDrop</code>.</p>



<a name="165315317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165315317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165315317">(May 10 2019 at 07:18)</a>:</h4>
<p>however, this interpretation assumes that <code>&amp;mut T</code> does not require the pointed-to memory to be a valid <code>T</code>, which some people are demanding</p>



<a name="165342855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165342855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165342855">(May 10 2019 at 14:56)</a>:</h4>
<p>oh I was assuming it also held for &amp;mut T</p>



<a name="165344342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165344342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165344342">(May 10 2019 at 15:14)</a>:</h4>
<p>(My understanding is the Box and &amp;mut T are "as if" they were T for most purposes)</p>



<a name="165516763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165516763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165516763">(May 13 2019 at 10:46)</a>:</h4>
<blockquote>
<p>like, if you wanted to define a type for which double-drops are fine, and then call drop_in_place on it twice, that should be fine in my un-thought-through opinion</p>
</blockquote>
<p>One consequence of saying that this is fine is that generic code cannot reason about these two different kind of types, so it has to assume that it can only drop things once.</p>



<a name="165516777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165516777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165516777">(May 13 2019 at 10:46)</a>:</h4>
<p>I had a similar question, where <code>Drop::drop</code> would panic, and the panic would be caught, whether you can try to re-drop a type.</p>



<a name="165516800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165516800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165516800">(May 13 2019 at 10:47)</a>:</h4>
<p>For example, when <code>Drop::drop</code> panics for an element of <code>Vec</code>, not all elements will be dropped, and their memory will be deallocated</p>



<a name="165516827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165516827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165516827">(May 13 2019 at 10:48)</a>:</h4>
<p>so trying to double drop the vector after the panic won't work</p>



<a name="165516884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165516884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165516884">(May 13 2019 at 10:48)</a>:</h4>
<p>the vector can't do anything about this, because even if it would correct, e.g., the len field, to leave the vector in a re-droppable state, the vector fields would be dropped, and the destructor of <code>RawVec</code> would deallocate the memory anyways</p>



<a name="165516921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165516921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165516921">(May 13 2019 at 10:49)</a>:</h4>
<p>fixing this would require making <code>RawVec</code> <code>ManuallyDrop</code> inside the vector, and correcting the length field when the element type implements drop. Feels like adding complexity to support something that shouldn't really happen in practice</p>



<a name="165518089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165518089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165518089">(May 13 2019 at 11:10)</a>:</h4>
<blockquote>
<p>oh I was assuming it also held for &amp;mut T</p>
</blockquote>
<p>it = what?</p>



<a name="165518123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165518123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165518123">(May 13 2019 at 11:11)</a>:</h4>
<blockquote>
<p>One consequence of saying that this is fine is that generic code cannot reason about these two different kind of types, so it has to assume that it can only drop things once.</p>
</blockquote>
<p>we have that already without any kind of special treatment like "deinit" bits. <code>Vec</code> is a type where calling <code>drop</code> twice is UB.</p>



<a name="165518141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165518141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165518141">(May 13 2019 at 11:11)</a>:</h4>
<blockquote>
<p>For example, when <code>Drop::drop</code> panics for an element of <code>Vec</code>, not all elements will be dropped, and their memory will be deallocated</p>
</blockquote>
<p>that's not true; <code>Vec</code> drops via the drop code for slices and that AFAIK properly resumes dropping with the next element.</p>



<a name="165519158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165519158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165519158">(May 13 2019 at 11:29)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> the update to the slice len will not be propagated to the vector len, the memory the slice refers to will be deallocated anyways, and the slice itself is dropped before the memory is deallocated, so I don't know how that matters</p>



<a name="165519278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165519278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165519278">(May 13 2019 at 11:31)</a>:</h4>
<blockquote>
<p>we have that already without any kind of special treatment like "deinit" bits. Vec is a type where calling drop twice is UB.</p>
</blockquote>
<p>Sure my point is that generic code (and users writing code in general) cannot assume that any type can be dropped more than once</p>



<a name="165519410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165519410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165519410">(May 13 2019 at 11:33)</a>:</h4>
<p>and in general, if drop fails, then the type must be leaked</p>



<a name="165519602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165519602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165519602">(May 13 2019 at 11:37)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> the update to the slice len will not be propagated to the vector len, the memory the slice refers to will be deallocated anyways, and the slice itself is dropped before the memory is deallocated, so I don't know how that matters</p>
</blockquote>
<p>...?<br>
You said "when Drop::drop panics for an element of Vec, not all elements will be dropped". I think that's wrong. When drop panics for an elem of <code>Vec</code>, it'll drop the next elem.</p>



<a name="165519688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165519688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165519688">(May 13 2019 at 11:38)</a>:</h4>
<blockquote>
<p>and in general, if drop fails, then the type must be leaked</p>
</blockquote>
<p>you mean when working "from the outside"? sure, I can't just hope that <code>drop</code> is idempotent or so.</p>



<a name="165519701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165519701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165519701">(May 13 2019 at 11:39)</a>:</h4>
<p>which is why I wonder why <span class="user-mention" data-user-id="137587">@Gankro</span> has these "deinit" bits in their model, that seems like an unnecessary complication.</p>



<a name="165519725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165519725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165519725">(May 13 2019 at 11:39)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> indeed, you are right, slice drop continues dropping the next element</p>



<a name="165519825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165519825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165519825">(May 13 2019 at 11:41)</a>:</h4>
<p>making <code>Drop::drop</code> for <code>Vec</code> idempotent should be trivial then</p>



<a name="165520192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165520192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165520192">(May 13 2019 at 11:46)</a>:</h4>
<p>We could have an <code>IdempotentDrop</code> auto trait for that</p>



<a name="165520206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165520206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165520206">(May 13 2019 at 11:46)</a>:</h4>
<p>If being able to tell these apart ever has applcations</p>



<a name="165529094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165529094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165529094">(May 13 2019 at 13:41)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> well I  do say at the top that "i don't think deinit is necessary"</p>



<a name="165529097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165529097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165529097">(May 13 2019 at 13:41)</a>:</h4>
<p>:)</p>



<a name="165529193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165529193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165529193">(May 13 2019 at 13:42)</a>:</h4>
<p>It's just kind've where I started when trying to picture ManuallyDrop, but later found it was seemingly unnecessary</p>



<a name="165529243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165529243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165529243">(May 13 2019 at 13:42)</a>:</h4>
<p>(similarly I thought it might be important to locals)</p>



<a name="165529293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165529293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165529293">(May 13 2019 at 13:43)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> whats the story for holding a raw ptr to a local? Is it UB if there's no other use keeping the var alive?</p>



<a name="165532451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165532451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165532451">(May 13 2019 at 14:16)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> well I  do say at the top that "i don't think deinit is necessary"</p>
</blockquote>
<p>fair^^ but I don't understand why they are even present optionally ;)</p>



<a name="165532490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165532490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165532490">(May 13 2019 at 14:16)</a>:</h4>
<p>seems to be "historic reasons" then^^</p>



<a name="165532504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165532504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165532504">(May 13 2019 at 14:17)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> whats the story for holding a raw ptr to a local? Is it UB if there's no other use keeping the var alive?</p>
</blockquote>
<p>using it becomes UB after a <code>StorageDead</code></p>



<a name="165533175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165533175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165533175">(May 13 2019 at 14:24)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> is it sufficient to do a dead load at the end of the scope? e.g. let _keep_alive = val;</p>



<a name="165535297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165535297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165535297">(May 13 2019 at 14:48)</a>:</h4>
<p>hmm, miri seems to think this is fine? <a href="https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=690492a439a7a641b3ddb23be8d8f4fe" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=690492a439a7a641b3ddb23be8d8f4fe">https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=690492a439a7a641b3ddb23be8d8f4fe</a></p>



<a name="165535367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165535367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165535367">(May 13 2019 at 14:49)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> is it sufficient to do a dead load at the end of the scope? e.g. let _keep_alive = val;</p>
</blockquote>
<p>this depends on how rustc inserts <code>StorageDead</code>...</p>



<a name="165536259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165536259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165536259">(May 13 2019 at 14:59)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> what is the model that allows a variable to store a reference that dangles? Is that StorageDead?</p>



<a name="165536362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165536362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165536362">(May 13 2019 at 15:00)</a>:</h4>
<p>I dont understand the question</p>



<a name="165536383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165536383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165536383">(May 13 2019 at 15:00)</a>:</h4>
<p><code>StorageDead</code> is an instruction, not a model</p>



<a name="165536404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165536404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165536404">(May 13 2019 at 15:00)</a>:</h4>
<p>and Rust lets you store dangling ptrs in a variable in safe code, so all models allow that</p>



<a name="165539539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165539539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165539539">(May 13 2019 at 15:34)</a>:</h4>
<p>wait doesn't that contradict that they're dereferencable()</p>



<a name="165539549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165539549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165539549">(May 13 2019 at 15:35)</a>:</h4>
<p>or is that only function args</p>



<a name="165541985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165541985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165541985">(May 13 2019 at 16:00)</a>:</h4>
<p>I am confused</p>



<a name="165541992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165541992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165541992">(May 13 2019 at 16:00)</a>:</h4>
<p>could you give an example?</p>



<a name="165547417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165547417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165547417">(May 13 2019 at 17:05)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> something having type &amp;T is supposed to indicate the compiler can freely read from it whever it wants, no? And a dangling reference is consequently UB?</p>



<a name="165557953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165557953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165557953">(May 13 2019 at 18:53)</a>:</h4>
<p><span class="user-mention" data-user-id="137587">@Gankro</span>  oh, sorry, missed the reference part. yeah references cannot dangle, though that does not answer the question of "<em>when</em> can they not dangle"</p>



<a name="165557968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose%20notes%20on%20my%20mental%20model%20of%20initialization/near/165557968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/loose.20notes.20on.20my.20mental.20model.20of.20initialization.html#165557968">(May 13 2019 at 18:53)</a>:</h4>
<p>but that has nothing to do with <code>StorageDead</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>